<template>
	<view class="card-container" @click="onCardClick">
		<!-- 左侧视频封面 -->
		<image class="card-image" src="@/static/video_preview/专业团队.png" />

		<!-- 右侧信息区域 -->
		<view class="card-content">
			<!-- 视频名称，限制长度并添加省略号 -->
			<text class="card-title">{{ truncate(video.videoName, 10) }} 🔥</text>

			<!-- 视频简介 -->
			<text class="video-remake">{{ truncate(video.videoRemake, 6) }}</text>

			<!-- 价格和购买按钮 -->
			<view class="footer">
				<text class="price">￥{{ video.price }}</text>
				<button class="buy-button">购买</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex';

	export default {
		props: {
			video: {
				type: Object,
				required: true
			}
		},
		methods: {
			...mapMutations(['setVideoAbout']),

			// 点击卡片时触发
			onCardClick() {
				// 将当前视频设置为 videoAbout
				this.setVideoAbout(this.video);

				// 跳转到视频展示页面
				uni.navigateTo({
					url: '/pages/pay_video/index'
				});
			},

			// 截断文本方法
			truncate(text, length) {
				return text.length > length ? text.slice(0, length) + "..." : text;
			}
		}
	};
</script>

<style>
.card-container {
  display: flex;
  width: 100%; 
  padding:  10px 0 10px 0;
  margin: 2px 0 2px 0 ;
  background-color: #ffffff;
  box-shadow: 0 2px  rgba(0, 0, 0, 0.1);
  cursor: pointer;
}

	.card-image {
		width: 120px;
		height: 80px;
		border-radius: 8px;
		object-fit: cover;
		margin-right: 10px;
	}

	.card-content {
		display: flex;
		flex-direction: column;
		flex: 1;
		justify-content: space-between;
	}

	.card-title {
		font-size: 16px;
		font-weight: bold;
		color: #333333;
	}

	.video-remake {
		font-size: 12px;
		color: #999999;
		margin-top: 4px;
	}

	.footer {
		display: flex;
		align-items: center;
		gap: 10px;
	}

	.price {
		width: 60%;
		font-size: 18px;
		font-weight: bold;
		color: #ff4500;
		margin-right: auto;
		/* 将价格对齐到左侧 */
	}

	.buy-button {
		min-width: 50px;
		width: 40%;
		padding: 0px 0px;
		background-color: #ff4500;
		color: #ffffff;
		/* border: none; */
		margin-left: auto;
		border-radius: 50px;
		font-size: 14px;
		cursor: pointer;
	}
</style>